<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class buoihocdukien_db 
	{
		public function Them($MaLopHoc, $NgayHoc, $MaTrangThai)
		{
			$sql = "INSERT INTO `tbl_buoihocdukien`(`MaLopHoc`, `NgayHoc`, `MaTrangThai`)
					VALUES ('$MaLopHoc', '$NgayHoc', '$MaTrangThai')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($MaLopHoc)
		{
			$sql = "DELETE FROM `tbl_buoihocdukien` WHERE `MaLopHoc` = '$MaLopHoc'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($MaLopHoc, $NgayHoc, $MaTrangThai)
		{
			$sql = "UPDATE `tbl_buoihocdukien`
					SET `NgayHoc` = '$NgayHoc', `MaTrangThai` = '$MaTrangThai'
					WHERE `MaLopHoc` = '$MaLopHoc'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($MaLopHoc, $NgayHoc, $MaTrangThai)
		{
			$sql = "SELECT * FROM `tbl_buoihocdukien` WHERE 1  ";
			if($MaLopHoc != "")
				$sql .= " AND `MaLopHoc` = '$MaLopHoc' ";

			if($NgayHoc != "0000-00-00")
				$sql .= " AND `NgayHoc` = '$NgayHoc' ";

			if($MaTrangThai != -1)
				$sql .= " AND `MaTrangThai` = '$MaTrangThai' ";
			$sql .= " ORDER BY `MaLopHoc` ASC, `NgayHoc` ASC ";
			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

